package com.lin.controller;

import dto.SysDeptDto;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.DeptService;
import util.ResponseVo;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Reference
    DeptService deptService;

    @GetMapping("/list")
    public ResponseVo getDeptList(){
        return ResponseVo.ok(deptService.getDeptList());
    }

//    @GetMapping("/treetable")
//    public ResponseVo treeTableList(){
//        return deptService.deptTreeTableData();
//    }

    @PostMapping("/add")
    @RequiresPermissions("dept_add")
    public ResponseVo addDept(SysDeptDto dept, BindingResult bindingResult){
        return deptService.addDept(dept);
    }

    @PostMapping("/update")
    @RequiresPermissions("dept_update")
    public ResponseVo updateDept(SysDeptDto dept, BindingResult bindingResult){
        return deptService.updateDept(dept);
    }

    @PostMapping("/delete")
    @RequiresPermissions("dept_delete")
    public ResponseVo deleteDept(Long id) {
        return deptService.deleteDept(id);
    }

}
